package com.wcc.mpmultidb.service.impl;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcc.mpmultidb.dao.slave.SlaveUserMapper;
import com.wcc.mpmultidb.entity.UserPg;
import com.wcc.mpmultidb.service.SlaveUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author wuch
 * @version 1.0
 * @date 2021/4/8 21:34
 */
@Service
public class SlaveUserServiceImpl extends ServiceImpl<SlaveUserMapper, UserPg> implements SlaveUserService {


    // @Transactional(rollbackFor = RuntimeException.class)//控制事务回滚
    @Async("asyncTaskExecutor")
    @DSTransactional
    @Override
    public void saveUser(UserPg userPg){
        try {
            Thread.sleep(2000);
            baseMapper.insert(userPg);
            System.out.println("slaveUserService更新成功");
            int i = 1/0;
        } catch (Exception e) {
            throw new RuntimeException("slaveUserServices失败");
        }
    }
}
